<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : "{{ urlfor "ArchivesController.DataGrid"}}"
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var params = checkQueryTableData(aoData)
			$('#search_key').val() ? params.Filter = $('#search_key').val() : '';
			$.post(sSource, JSON.stringify(params),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
			{"mDataProp" : "Mobile","sTtile" : "Mobile", "bSortable": false}
			,{"mDataProp" : "Realname","sTtile" : "RealName", "bSortable": false}
			,{"mDataProp" : "Age","sTtile" : "Age", "bSortable": false}
			,{"mDataProp" : "Sex","sTtile" : "Sex", "bSortable": false}
			,{"mDataProp" : "Birthday","sTtile" : "Birthday", "bSortable": false}
			,{"data" : "Address", "bSortable": false}
			,{   
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"10%",
				"render": function ( data, type, full, meta ) {
					btns = '<a href="javascript:;" class="am-btn am-btn-success am-btn-xs" onclick="return selectArchives('+ meta.row +');">选择</a>';
					return btns;  
				}  
			 } 
		]
		,"aLengthMenu":[10, 20, 30, 100]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	
	$("#searchsubmit").bind("click", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
	});
    $('#search_key').keydown(function (event) {
        if(event.keyCode==13){
            var value = $(this).val();
            if(value != '') {
                $("#searchsubmit").click();
            }
        }
    });
	$('#dataTables tbody').on('dblclick','tr', function () {
		var i = tables.row(this).index();
		selectArchives(i);
	});

	function selectArchives(d) {
		parent.receiveFormData(tables.row(d).data());
		return false;
	}
	
</script>
